#include <iostream>
#include "XThread.h"
#include "XMutex.h"
#include <windows.h>
using namespace std;
static char buf[1024] = { 0 };
//CRITICAL_SECTION section;
static XMutex mutex;
class MyThread :public XThread
{
public:
	void Main()
	{
		cout << "In MyThread" << endl;
		for (;;)
		{
			int size = sizeof(buf);
			//EnterCriticalSection(&section);
			mutex.Lock();
			for (int i = 0; i < size; i++)
			{
				buf[i] = c;
				Sleep(1);
			}
			buf[size-1] = '\0';
			cout << "["<<buf<<"]" << endl;
			mutex.Unlock(); 
			//LeaveCriticalSection(&section);
			Sleep(1);
		}
		/*Sleep(10000);*/
	}
	char c;
};
int main()
{
	//InitializeCriticalSection(&section);
	MyThread myt1;
	myt1.c = 'A';
	MyThread myt2;
	myt2.c = 'B';

	myt1.Start();
	myt2.Start();
	getchar();
	return 0;
}